package com.ctgu.j08.controller;

import com.ctgu.j08.service.DeviceService;
import com.ctgu.j08.vo.Device;
import com.ctgu.j08.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/5/29 15:30
 */
@Controller
@RequestMapping("/device")
public class DeviceController {
    @Resource
    private DeviceService deviceService;

    @PostMapping("/add")
    @ApiOperation("添加设备信息")
    @ResponseBody
    public Result addDevice(@RequestBody Device device){
        System.out.println("添加的设备"+device);
        return deviceService.addDevice(device);
    }

    @PutMapping("/edit")
    @ApiOperation("更新设备信息")
    @ResponseBody
    public Result editDevice(@RequestBody Device device)
    {
        return deviceService.editDevice(device);
    }

    @DeleteMapping("/del/{deId}")
    @ApiOperation("根据id删除设备")
    @ResponseBody
    public Result delDeviceById(@PathVariable("deId") int deId){
        System.out.println("删除Controller");
        return deviceService.delDevice(deId);
    }

    @GetMapping("/getAll")
    @ApiOperation("获取全部设备信息")
    @ResponseBody
    public Result getAllDeviceInfo()
    {
        return deviceService.getAllDeviceInfo();
    }

    @GetMapping("/search/{deName}")
    @ApiOperation("查询设备信息")
    @ResponseBody
    public Result searchDeviceInfo(@PathVariable("deName") String deName)
    {
        System.out.println("查询用户Controller");
        return deviceService.searchDeviceByName(deName);
    }
}
